package eval.cm.xml.parser.simple.parser.impl;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import eval.cm.xml.parser.simple.parser.Parser;
import eval.cm.xml.parser.simple.parser.ParserFactory;

public class DefaultParserFactory implements ParserFactory {

	
	public Parser buildParser(final Class<? extends Parser> parserClass) {
		return createClassInstance(parserClass);
	}
	
	private static Parser createClassInstance( final Class<? extends Parser> clazz ) {
		try {
			Constructor<? extends Parser> cnstr = clazz.getConstructor(new Class[]{});
			return cnstr.newInstance();
		} catch (SecurityException e) {
			throw new RuntimeException(e);
		} catch (NoSuchMethodException e) {
			throw new RuntimeException(e);
		} catch (IllegalArgumentException e) {
			throw new RuntimeException(e);
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		} catch (InvocationTargetException e) {
			throw new RuntimeException(e);
		}
		
	}

}
